/*
package org.example.cardgame.utils;

import com.alibaba.fastjson.JSON;
import org.example.cardgame.entity.Card;
import org.springframework.beans.BeanUtils;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

*/
/**
 * @Author juanita.ren
 * @Date 2024/11/11 22:20
 * @Version 1.0
 *//*


public class CardCompareGroup {
    private static final int WEIHGT_ROYAL_FLUSH = 10;
    private static final int WEIHGT_STRAIGHT_FLUSH = 9;
    private static final int WEIHGT_FOUR_KIND = 8;
    private static final int WEIHGT_FULL_HOUSE = 7;
    private static final int WEIHGT_FLUSH = 6;
    private static final int WEIHGT_STRAIGHT = 5;
    private static final int WEIHGT_THREE_KIND = 4;
    private static final int WEIHGT_TWO_PAIRS = 3;
    private static final int WEIHGT_ONE_PAIR = 2;
    private static final int WEIHGT_HIGH_CARD = 1;
    private List<Card> cardList;
    private long maxWeight;
    private int type;
    private List<Card> maxList;

    public CardCompareGroup(List<Card> cardList) {
        this.cardList = cardList;
        this.dealWeight();
    }

    public long getMaxWeight() {
        return this.maxWeight;
    }

    public void setMaxWeight(long maxWeight) {
        this.maxWeight = maxWeight;
    }

    public int getType() {
        return this.type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public List<Card> getMaxList() {
        return this.maxList;
    }

    public void setMaxList(List<Card> maxList) {
        this.maxList = maxList;
    }

    private void dealWeight() {
        List<Card> cardList = (List)this.cardList.stream().map((card) -> {
            Card cardClone = new Card();
            BeanUtils.copyProperties(card, cardClone);
            if (cardClone.getNumber() == 1) {
                cardClone.setNumber(14);
            }

            return cardClone;
        }).collect(Collectors.toList());
        List<Card> maxList = null;
        int maxType = -1;
        List<Integer> numberList = (List)cardList.stream().map(Card::getNumber).distinct().sorted().collect(Collectors.toList());
        Map<Integer, List<Card>> numberGroup = (Map)cardList.stream().collect(Collectors.groupingBy(Card::getNumber));
        Map<Integer, List<Card>> typeGroup = (Map)cardList.stream().collect(Collectors.groupingBy(Card::getType));
        List<List<Integer>> linkGroup = new ArrayList();

        for(int i = 0; i < numberList.size() - 4; ++i) {
            if ((Integer)numberList.get(i) == (Integer)numberList.get(i + 4) - 4) {
                linkGroup.add(numberList.subList(i, i + 5));
            }
        }

        List<Card> sameType = (List)typeGroup.values().stream().filter((link) -> {
            return link.size() >= 5;
        }).findFirst().orElse(null);
        if (!linkGroup.isEmpty()) {
            Collections.reverse(linkGroup);
        }

        if (sameType != null) {
            boolean hasLink = false;
            if (!linkGroup.isEmpty()) {
                Iterator var10 = linkGroup.iterator();

                while(var10.hasNext()) {
                    List<Integer> linkList = (List)var10.next();
                    if (sameType.stream().allMatch((card) -> {
                        return linkList.contains(card.getNumber());
                    })) {
                        hasLink = true;
                        maxList = (List)sameType.stream().filter((card) -> {
                            return linkList.contains(card.getNumber());
                        }).collect(Collectors.toList());
                        if ((Integer)linkList.get(linkList.size() - 1) == 14) {
                            maxType = 10;
                        } else {
                            maxType = 9;
                        }
                        break;
                    }
                }
            }

            if (!hasLink) {
                maxType = 6;
                maxList = (List)sameType.stream().sorted(Comparator.comparing(Card::getNumber, Comparator.reverseOrder())).limit(5L).collect(Collectors.toList());
            }
        }

        if (maxType == -1 && !linkGroup.isEmpty()) {
            maxType = 5;
            maxList = new ArrayList();
            Iterator var16 = ((List)linkGroup.get(0)).iterator();

            while(var16.hasNext()) {
                Integer num = (Integer)var16.next();
                ((List)maxList).add(cardList.stream().filter((card) -> {
                    return card.getNumber() == num;
                }).findFirst().orElse(new Card()));
            }
        }

        List<List<Card>> sameNumberList = (List)numberGroup.values().stream().sorted(Comparator.comparing((list) -> {
            return list.size() * 1000 + ((Card)list.get(0)).getNumber();
        }, Comparator.reverseOrder())).collect(Collectors.toList());
        if (((List)sameNumberList.get(0)).size() == 4) {
            if (maxType < 8) {
                maxType = 8;
                maxList = new ArrayList();
                ((List)maxList).addAll((Collection)sameNumberList.get(0));
                ((List)maxList).add(((List)sameNumberList.get(1)).get(0));
            }
        } else if (((List)sameNumberList.get(0)).size() == 3) {
            if (((List)sameNumberList.get(1)).size() >= 2) {
                if (maxType < 7) {
                    maxType = 7;
                    maxList = new ArrayList();
                    ((List)maxList).addAll((Collection)sameNumberList.get(0));
                    ((List)maxList).addAll(((List)sameNumberList.get(1)).subList(0, 2));
                }
            } else if (maxType < 4) {
                maxType = 4;
                maxList = new ArrayList();
                ((List)maxList).addAll((Collection)sameNumberList.get(0));
                ((List)maxList).add(((List)sameNumberList.get(1)).get(0));
                ((List)maxList).add(((List)sameNumberList.get(2)).get(0));
            }
        } else if (((List)sameNumberList.get(0)).size() == 2) {
            if (((List)sameNumberList.get(1)).size() == 2) {
                if (maxType < 3) {
                    maxType = 3;
                    maxList = new ArrayList();
                    ((List)maxList).addAll((Collection)sameNumberList.get(0));
                    ((List)maxList).addAll((Collection)sameNumberList.get(1));
                    ((List)maxList).add(((List)sameNumberList.get(2)).get(0));
                }
            } else if (maxType < 2) {
                maxType = 2;
                maxList = new ArrayList();
                ((List)maxList).addAll((Collection)sameNumberList.get(0));
                ((List)maxList).add(((List)sameNumberList.get(1)).get(0));
                ((List)maxList).add(((List)sameNumberList.get(2)).get(0));
                ((List)maxList).add(((List)sameNumberList.get(3)).get(0));
            }
        }

        if (maxType == -1) {
            maxType = 1;
            maxList = (List)cardList.stream().sorted(Comparator.comparing(Card::getNumber, Comparator.reverseOrder())).limit(5L).collect(Collectors.toList());
        }

        long maxWeight;
        maxWeight = 0L;
        int i;
        label81:
        switch (maxType) {
            case 1:
                i = 0;

                while(true) {
                    if (i >= ((List)maxList).size()) {
                        break label81;
                    }

                    maxWeight += (long)((Card)((List)maxList).get(i)).getNumber() * (long)Math.pow(10.0, (double)((5 - i) * 2));
                    ++i;
                }
            case 2:
            case 3:
            case 4:
            case 7:
            case 8:
                maxWeight = (long)maxType * (long)Math.pow(10.0, 12.0);
                List<Integer> numList = (List)((List<Card>)maxList).stream().map(Card::getNumber).distinct().collect(Collectors.toList());
                Stream var10000 = numberGroup.keySet().stream();
                numList.getClass();
                List<Integer> numbers = var10000.filter(numList::contains).sorted(Comparator.comparing((numx) -> {
                    return numx;
                }, Comparator.reverseOrder())).collect(Collectors.toList());
                i = 0;

                while(true) {
                    if (i >= numbers.size()) {
                        break label81;
                    }

                    maxWeight += (long)(Integer)numbers.get(i) * (long)Math.pow(10.0, (double)((5 - i) * 2));
                    ++i;
                }
            case 5:
            case 6:
            case 9:
            case 10:
                maxWeight = (long)maxType * (long)Math.pow(10.0, 12.0) + (long)((List<Card>)maxList).stream().mapToInt(Card::getNumber).max().orElse(0);
        }

        ((List<Card>)maxList).forEach((card) -> {
            if (card.getNumber() == 14) {
                card.setNumber(1);
            }

        });
        this.maxWeight = maxWeight;
        this.maxList = (List)maxList;
        this.type = maxType;
    }

    public static void main(String[] args) {
        List<Card> cardList = new ArrayList();
        cardList.add(new Card(2, 13));
        cardList.add(new Card(1, 13));
        cardList.add(new Card(3, 13));
        cardList.add(new Card(0, 5));
        cardList.add(new Card(2, 5));
        cardList.add(new Card(1, 10));
        cardList.add(new Card(1, 9));
        CardCompareGroup group = new CardCompareGroup(cardList);
        System.out.println(group.getType());
        System.out.println(group.getMaxWeight());
        System.out.println(JSON.toJSONString(group.getMaxList()));
    }
}
*/
